home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindspring.com!usenet
- From: rudd@mindspring.com (Justin Rudd)
- Newsgroups: comp.lang.c++
- Subject: Re: Null Pointer Assignment
- Date: Thu, 14 Mar 1996 05:16:51 GMT
- Organization: MindSpring Enterprises
- Message-ID: <4i8a68$gfr@B1FF.mindspring.com>
- References: <4i84kd$1lh4@saba.info.ucla.edu>
- Reply-To: rudd@mindspring.com
- NNTP-Posting-Host: rudd.mindspring.com
- X-Newsreader: Forte Free Agent v0.55
-
- mael1@ucla.edu (Matt Waggoner) wrote:
-
- >I have a class called City that contains a private data member, char *name.
- >The constructor receives an argument called char *s. The constructor looks
- >like this:
-
- >City::City(char *s)
- >{
- > name = new char(strlen(s));
- > name = s;
- >}
-
- OK...first off you have name pointing to a temporary variable s. Do
- this instead.
-
- City::City( char* s )
- {
- name = new char(strlen(s)+1]; //+1 for \0
- strcpy(name,s);
- }
-
- This should do it for ya....if not...flame me ;-)
-
- >The program works fine, but I get a NULL POINTER ASSIGNMENT whenever it
- >terminates. What the HELL causes this, and how do I get rid of it? A quick
- >answer would be good, I'm under a bit of time pressure... thanks in advance.
-
-
-